﻿using System;
using System.IO;

namespace UDS.Management.Data.Package
{
    /// <summary>
    /// Represents the content of a single SQL script
    /// </summary>
    public class SqlSource : ScriptSource
    {
        private SqlCommandReader m_content;

        public SqlSource()
        {
        }

        public SqlSource(string name, Stream stream) :
            base(name, stream)
        {
            Initialize(name, stream);
        }

        public SqlSource(string name, TextReader reader) :
            base(name, null)
        {
            this.m_content = new SqlCommandReader(reader);
        }

        internal override void Initialize(string name, Stream stream)
        {
            base.Initialize(name, stream);
            if (stream != null)
            {
                this.m_content = new SqlCommandReader(new StreamReader(stream));
            }
        }
        /// <summary>
        /// A SqlCommandReader used to retrieve the content of the script.
        /// </summary>
        public SqlCommandReader Content
        {
            get
            {
                return m_content;
            }
        }

        #region IDisposable Members

        public override void Dispose()
        {
            base.Dispose();
            if (m_content != null)
            {
                m_content.Close();
            }
        }

        #endregion
    }
}
